package com.sino.operation.util;

import cn.hutool.core.util.RandomUtil;
import com.sino.operation.peripheral.esc.request.*;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.peripheral.esc.request.core.EscCore2110Param;
import com.sino.operation.peripheral.esc.request.core.EscCore4010Param;
import com.sino.operation.peripheral.esc.request.core.EscCore4020Param;
import com.sino.operation.peripheral.esc.request.core.EscCoreParam;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName EscRequestTestUtil
 * @Description TOD
 * @Author 北陈
 * @Date 2021/9/27 15:53
 * @Version 1.0
 */
@Slf4j
public class EscRequestTestUtil {
    public static EscRequestParam getEscRequestParam(CenterResponseEntity entity){
        EscRequestParam escRequestParam = new EscRequestParam();
        EscSysHead escSysHead = new EscSysHead();
        EscAppHead escAppHead = new EscAppHead();
        EscBody escBody = new EscBody();
        CoreHead coreHead = new CoreHead();
        escRequestParam.setEscAppHead(escAppHead);
        escRequestParam.setEscSysHead(escSysHead);
        escBody.setCoreHead(coreHead);
        escRequestParam.setEscBody(escBody);
        return escRequestParam;
    }

    public static EscCoreParam getEscCoreParam(String journal, String coreTranCode, String escToken){
        EscCoreParam escCoreParam = new EscCoreParam();
        EscSysHead escSysHead = getEscSysHead(journal);
        escSysHead.setServiceCode(coreTranCode);
        EscAppHead escAppHead = new EscAppHead();
        LocalHead localHead = getLocalHead(coreTranCode,escToken);
        escCoreParam.setEscAppHead(escAppHead);
        escCoreParam.setEscSysHead(escSysHead);
        escCoreParam.setLocalHead(localHead);
        return escCoreParam;
    }


    public static EscCore4010Param getEscCore4010Param(String journal,String coreTranCode,String escToken){
        EscCore4010Param escCore4010Param = new EscCore4010Param();
        EscSysHead escSysHead = getEscSysHead(journal);
        escSysHead.setServiceCode(coreTranCode);
        EscAppHead escAppHead = new EscAppHead();
        LocalHead localHead = getLocalHead(coreTranCode,escToken);
        escCore4010Param.setEscAppHead(escAppHead);
        escCore4010Param.setEscSysHead(escSysHead);
        escCore4010Param.setLocalHead(localHead);
        return escCore4010Param;
    }

    public static EscCore2110Param getEscCore2110Param(String journal){
        EscCore2110Param escCore2110Param = new EscCore2110Param();
        EscAppHead escAppHead = new EscAppHead();
        EscSysHead escSysHead = getEscSysHead(journal);
        LocalHead localHead = new LocalHead();
        escCore2110Param.setEscAppHead(escAppHead);
        escCore2110Param.setEscSysHead(escSysHead);
        escCore2110Param.setLocalHead(localHead);
        return escCore2110Param;
    }

    public static EscCore4020Param getEscCore4020Param(String journal){
        EscCore4020Param escCore4020Param = new EscCore4020Param();
        EscAppHead escAppHead = new EscAppHead();
        EscSysHead escSysHead = getEscSysHead(journal);
        LocalHead localHead = new LocalHead();
        escCore4020Param.setEscAppHead(escAppHead);
        escCore4020Param.setEscSysHead(escSysHead);
        escCore4020Param.setLocalHead(localHead);
        return escCore4020Param;
    }

    public static EscSysHead getEscSysHead(String journalNo){
        EscSysHead escSysHead = new EscSysHead();
        escSysHead.setServiceCode("SX_BPR_11200");
        escSysHead.setSourceSvrId("10.64.20.145");
        escSysHead.setServiceScene("01");
        escSysHead.setConsumerId("11200");
        escSysHead.setChannelCode("1120000");
        escSysHead.setConsumerSeqNo(journalNo);
        String seq="G11700"+TimeUtil.getDateTime()+"00000"+ RandomUtil.randomNumbers(5);
        log.info("流水号:"+journalNo+"\n全局流水号:"+seq);
        escSysHead.setBussSeqNo(seq);
        escSysHead.setTranDate(TimeUtil.getDateTime());
        escSysHead.setTranTimestamp(TimeUtil.getTimestamp());
        return escSysHead;
    }

    public static LocalHead getLocalHead(String coreTranCode,String escToken){
        return LocalHead.builder().reqTenant("sxyh").reqPartId("1120000")
                .reqPartVersion("V1.0").reqToken(escToken)
                .svcTranNo("SX_00101_"+coreTranCode)
                .svcVerNo("V1.0").build();
    }
    public static EscAppHead getAppHead(){
        return EscAppHead.builder().userId("000001").userPassword("000001").userType("01").build();
    }
}
